package com.dubbo.mapper.auth;

import com.dubbo.domain.auth.Permission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 权限表mapper
 * @author chenluqiang
 * @date 2018年12月14日 上午10:02:53 
 *
 */
public interface PermissionMapper extends Mapper<Permission>{
	
	/**
	 * 根据用户id获取该用户的权限菜单名称
	 * @author chenluqiang
	 * @date 2018年12月14日 上午10:11:42 
	 * @param userId 用户id
	 * @return
	 */
	@Select("SELECT " + 
			"	upn.permission " + 
			"FROM " + 
			"	u_permission upn " + 
			"LEFT JOIN u_role_permission urp ON urp.permissionId = upn.id " + 
			"LEFT JOIN u_role ure ON ure.id = urp.roleId " + 
			"LEFT JOIN u_role_user uru ON uru.roleId = ure.id " + 
			"WHERE " + 
			"	uru.userId = #{userId}")
	List<String> getPermissionsByUserId(@Param("userId") String userId);
}